package com.cskaoyan.processor;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @author stone
 * @date 2021/11/19 14:22
 */
public class ProxyUtils {
    public static Object getServiceProxy(Class<?> aClass) throws IllegalAccessException, InstantiationException {
        Object object = aClass.newInstance();
        Object proxy = Enhancer.create(aClass, new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                System.out.println("hello");
                //object != bean
                Object invoke = method.invoke(object, objects);
                System.out.println("world");
                return invoke;
            }
        });
        return proxy;
    }
}
